//
//  ViewController.m
//  ShareItemWX
//
//  Created by 吴德明 on 16/7/14.
//  Copyright © 2016年 吴德明. All rights reserved.
//
#import <Social/Social.h>
#import "ViewController.h"
#import "SharedItem.h"
#import "CustomerActivity.h"
#import "ShareTool.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    UIButton *Button = [UIButton buttonWithType:UIButtonTypeCustom];
    Button.frame = CGRectMake(0, 0, 100, 100);
    Button.center = self.view.center;
    Button.backgroundColor = [UIColor blueColor];
    [Button setTitle:@"分享到微信" forState:UIControlStateNormal];
    [Button addTarget:self action:@selector(shareWX) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Button];
    
    
    
}

 /** 分享到微信 以九宫格的方式*/
-(void)shareWX{
    
    if(![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]){
        NSLog(@"不可用");
    }else{
        NSLog(@"可用");
    }
//    
//     /** 图片数组*/
//    NSArray *array_photo = @[@"http://img.meifajia.com/o1aneipt09eCl5bqQp4ifbQdTHlKIJfq.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneipt2fbZm38Zct4DH92p-ez7-fXt.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneiocd24Y6jK8uQA8-8y-47H6vRe7.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneiocdd94h6ld4kQJh8PcpjGSkORS.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneiocdd94h6ld4kQJh8PcpjGSkORS.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneipt09eCl5bqQp4ifbQdTHlKIJfq.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneioccpacV1LVg2AfG9fbYl8zN1So.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneipt0haf1zwepSkxx9okI0W34t05.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneipt09eCl5bqQp4ifbQdTHlKIJfq.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneipt09eCl5bqQp4ifbQdTHlKIJfq.jpg?imageView2/1/w/360/h/480/q/85",@"http://img.meifajia.com/o1aneipt09eCl5bqQp4ifbQdTHlKIJfq.jpg?imageView2/1/w/360/h/480/q/85"];
//    
//    
//    
//    NSMutableArray *array = [[NSMutableArray alloc]init];
//    for (int i = 0; i <1; i++) {
//        NSString *URL = array_photo[i];
//        NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:URL]];
//        UIImage *imagerang = [UIImage imageWithData:data];
//        
//        NSString *path_sandox = NSHomeDirectory();
//        NSString *imagePath = [path_sandox stringByAppendingString:[NSString stringWithFormat:@"/Documents/ShareWX%d.jpg",i]];
//        [UIImagePNGRepresentation(imagerang) writeToFile:imagePath atomically:YES];
//        
//        NSURL *shareobj = [NSURL fileURLWithPath:imagePath];
//        
//         /** 这里做个解释 imagerang : UIimage 对象  shareobj:NSURL 对象 这个方法的实际作用就是 在吊起微信的分享的时候 传递给他 UIimage对象,在分享的时候 实际传递的是 NSURL对象 达到我们分享九宫格的目的 */
//        
//        SharedItem *item = [[SharedItem alloc] initWithData:imagerang andFile:shareobj];
//        
//        [array addObject:item];
//    }
//	
//    
//    UIActivityViewController *activityViewController =[[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];
//    
//    //activityViewController.excludedActivityTypes = @[UIActivityTypePostToFacebook,UIActivityTypeAirDrop];
//
//    
//    [self presentViewController:activityViewController animated:TRUE completion:nil];
//    
//
//    
    
    
    NSMutableArray *items = [[NSMutableArray alloc] init];
    [items addObject:@"分享的title"];
    [items addObject:[UIImage imageNamed:@"1"]];
    [items addObject:@"https://www.baidu.com"];
    
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    NSMutableArray *excludedActivityTypes =  [NSMutableArray arrayWithArray:@[UIActivityTypeAirDrop, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypeMail, UIActivityTypePostToTencentWeibo, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePostToTwitter]];
    activityViewController.excludedActivityTypes = excludedActivityTypes;
    [self presentViewController:activityViewController animated:YES completion:nil];
    activityViewController.completionWithItemsHandler = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
        NSLog(@"%@  ----   %@", activityType, returnedItems);
    };
    
    [[[ShareTool alloc] init] shareWithTitle:@"分享的title" description:@"描述信息" url:@"http://www.baidu.com" image:[UIImage imageNamed:@"1"] completionHandler:^(UIActivityType  _Nullable activityType, BOOL completed) {
        NSLog(@"%@  %d", activityType, completed);
    }];
}





@end
